#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
using namespace std;
int main()
{
    char flag[2];
    scanf("%s", flag);

    int n;
    scanf("%d", &n);
    int num = 0;
    if (flag[0] == '*' || flag[0] == '=')
    {
        while (n)
        {
            num += n;
            n--;
        }
        cout << num << endl;
    }
    else if (flag[0] == ',')
    {
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= i; j++)
                num++;
        cout << num << endl;
    }
    else
    {
        int t = flag[0] - '0';
        if (n >= t) num += t + 1 + (n - t);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= i; j++)
            {
                int res = i * j;
                string s = to_string(res);
                for (int i = 0; i < s.size(); i++)
                    if (s[i] == flag[0])
                        num++;
            }
        cout << num << endl;
    }

}